import axios from 'axios'
import { UserState } from '@/store/modules/user/types'
import { DEFAULT_LAYOUT } from '@/router/routes/base'

// 登录
export interface LoginData {
	name: string

	password: string
}

// 菜单
export interface MenuData {
	children?: MenuData[]

	component?: string | typeof DEFAULT_LAYOUT | unknown

	meta: {
		icon?: string
		locale: string
		requiresAuth: boolean
		order?: number
	}

	name: string

	path: string
}

export interface LoginRes {
	token: string
}

export function login(data: LoginData) {
	return axios.post<LoginRes>('/login', data)
}

export function logout() {
	return axios.post<LoginRes>('/logout')
}

export function getUserInfo() {
	return axios.post<UserState>('/sys_user/getInfo')
}

// 获取菜单信息
export function getMenuList() {
	return axios.post<MenuData[]>('/system/menu/getRouters')
}
